﻿
/**
*跟单
*/
Chenxin.UI.TraceForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/traceHandler.ashx',
    id: 'traceWin',
    renderTo: 'jqm_trace',
    initFormValidator: function() {
        var _this = this;
        $("#houseTraceAddTxtNoticeTime").focus(function() {
            WdatePicker({ oncleared: function() { $(this).blur(); }, onpicked: function() { $(this).blur(); } })
        }).formValidator({ validatorgroup: this.id,
            onshow: "请输入提醒时间！", onfocus: "请输入提醒时间", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "提醒时间不能为空！" }, onerror: "提醒时间不能为空！"
        });
        $("#houseTraceAddTxtANoticeContent").formValidator({ validatorgroup: this.id,
            onshow: "请输入提醒内容！", onfocus: "请输入提醒内容", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { emptyerror: "提醒内容不能为空！" }, onerror: "提醒内容不能为空！"
        });
        $("#houseTraceAddTxtSummary").formValidator({ validatorgroup: this.id,
            onshow: "跟单内容！", onfocus: "跟单内容", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { emptyerror: "跟单内容不能为空！" }, onerror: "跟单内容不能为空！"
        }).functionValidator({
            fun: function(val, elem) {
                if (val.trim() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "跟单内容不能为空！"
        });
    },
    createForm: function() {
        return formCommon.houseTraceForm('trace');
    },
    createComboList: function() {
        var traceType = new Chenxin.UI.Combo({
            containerId: '#followStyle',
            name: 'TraceType',
            tbxWidth: 45,
            required: true,
            items: comboCommon.traceStyle
        });

        return [traceType];
    },
    initEvent: function() {
        var _this = this;
        $('#trace_Save').live('click', function() {
            _this.save();
        });
        $('#trace_Cancle').live('click', function() {
            _this.isNotice = '';
            $('#tr_noticetime').hide();
            $('#tr_noticecontent').hide();
            _this.hide();
        });
        $('#houseTraceAddIsNotice').live('click', function() {
            if (this.checked) {
                $('#tr_noticetime').show();
                $('#tr_noticecontent').show();
            } else {
                $('#houseTraceAddTxtNoticeTime').val("");
                $('#houseTraceAddTxtANoticeContent').val("");
                $('#tr_noticetime').hide();
                $('#tr_noticecontent').hide();
            }
            _this.isNotice = this.checked;
        });
    },
    customerFormVal: function() {
        if ($('houseTraceAddTxtSummary').val()) {
            this.errorMessage = '请填写跟单内容！';
            return false;
        } else {
            return true;
        }
    },
    formValidator: function(model) {
        var status = true;
        if ($('#houseTraceAddIsNotice').attr('checked')) {
            $("#houseTraceAddTxtSummary").unFormValidator(false);
            $("#houseTraceAddTxtNoticeTime").unFormValidator(false);
            $("#houseTraceAddTxtANoticeContent").unFormValidator(false);
            status = jQuery.formValidator.pageIsValid(this.id) && this.checkCombo();
        } else {
            $("#houseTraceAddTxtNoticeTime").unFormValidator(true);
            $("#houseTraceAddTxtANoticeContent").unFormValidator(true);
            $("#houseTraceAddTxtSummary").unFormValidator(false);
            status = jQuery.formValidator.pageIsValid(this.id) && this.checkCombo();
        }
        if (!status) {
            alert(this.errorMessage || '请填写完必填(选)项再进行表单提交！');
        }
        return status;

    },
    initComponent: function() {
        Chenxin.UI.TraceForm.superclass.initComponent.call(this);
    }
});